package model.filemanager;

import java.util.List;

import com.google.appengine.api.datastore.Entity;

/**
 * Get the statistics for each user
 * @author Dat
 *
 */
public class UserQuota {
	
	public long maximumBytes = 100000000;
	
	private FileManager fm;
	private String user;
	
	public UserQuota() {
		user = "test";
	}
	
	public UserQuota(String user) {
		this.user = user;
		fm = new FileManager(user);
	}
	
	/*
	 * Get the number of files of a certain type
	 * @param type of the file: image, video, audio or null  
	 */
	public int getNumberOfFiles(String type) {
		return fm.GetEntities(type, null, true).size();			
	}
	
	/*
	 * Get total storage of all files of a certain type
	 * @param type of the files: image video audio null
	 */
	public long getTotalStorage(String type) {
		List<Entity> entityList = fm.GetEntities(type, null, true);
		long totalStorage = 0;
		for (Entity entity : entityList) {
			totalStorage += (Long)entity.getProperty("size");
		}
		return totalStorage;
	}	

}
